#include<bits/stdc++.h>
using namespace std;
typedef long ll;
const int N=2e5+10;
int n;
ll a[N],dp[110][110];
void solve(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",a+i);
    }
    if(n<=15){
        ll ans=0;
        int lst[2];
        for(int msk=0;msk<(1<<n);msk++){
            lst[0]=lst[1]=-1;
            ll sum=0;
            for(int i=1;i<=n;i++){
                int cur=(msk>>(i-1)&1);
                if(lst[cur]!=-1&&a[lst[cur]]==a[i])sum+=a[i];
                lst[cur]=i;
            }
            ans=max(ans,sum);
        }
        printf("%lld\n",ans);
        return;
    }
    if(n<=100){
        memset(dp,-0x3f,sizeof(dp));
        dp[0][0]=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<=i;j++){
                if(dp[i][j]>=0){
                    ll dd=0;
                    if(a[i]==a[i+1])dd=a[i];
                    dp[i+1][j]=max(dp[i+1][j],dp[i][j]+dd);
                    ll cur=0;
                    for(int k=i+2;k<=n;k++){
                        dd=0;
                        if(a[i]==a[k])dd=a[i];
                        if(a[j]==a[k-1])dp[k][k-1]=max(dp[k][k-1],dp[i][j]+dd+cur+a[j]);
                        else dp[k][k-1]=max(dp[k][k-1],dp[i][j]+dd+cur);
                        if(a[k]==a[k-1])cur+=a[k];
                    }
                }
            }
        }
        ll ans=0;
        for(int i=0;i<=n;i++)ans=max(ans,dp[n][i]);
        printf("%lld\n",ans);
        return;
    }
}
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--)solve();
	return 0;
}
/*
things to check:
1. freopen
2. int / long long
3. array bounds
4. clear when multi-tests
5. MOD
g++ color.cpp -o color -Wall -Wextra -Wshadow -Wconversion
*/